IRR

class IRR @JvmOverloads constructor(val cashFlows: List<ROICashFlowEntry>?, val allowAllZerosCashFlows: Boolean = false, var title: String? = null, val currency: CurrencyType? = null, val account: Account? = null)

Internal Rate of Return (IRR) calculation engine, along with useful IRR functions.

This class performs XIRR (Extended Internal Rate of Return) type calculations (aka IRR with non-periodic (irregular) cashflows)

  • XIRR calculates the annualised return from a series of cashflows that occur on irregular dates.

  • It finds the interest rate that makes the present value of all cashflows equal to zero.

Author

Stuart Beesley - August 2025

Since

MD2027

Parameters

cashFlows

Optionally specify the list of cash flows for the IRR calculation, or null (which will be invalid).

allowAllZerosCashFlows

Allows otherwise valid cashflows with values of all (or near-) zeros to report as valid.

title

Optional title for this IRR calculation.

currency

Optionally specify the currency used to create the cash flows (e.g. dollars, euro, etc., not shares), or null.

account

Optionally specify the account used to create the cash flows (e.g. security account), or null.

See also

Constructors

Link copied to clipboard
constructor(cashFlows: List<ROICashFlowEntry>?, allowAllZerosCashFlows: Boolean = false, title: String? = null, currency: CurrencyType? = null, account: Account? = null)

Creates a new IRR calculation instance for IRR calculations and results

Types

Link copied to clipboard
data class CalculationResult(val strategy: IRR.SolveStrategy? = null, val seedRate: Double? = null, val irr: Double? = null, val didSolve: Boolean = false)

Stores a single IRR calculation result (which may or may not have been successful)

Link copied to clipboard
object Companion
Link copied to clipboard

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

clears all previous IRR calculation results - i.e. as if no calculations have been performed

Link copied to clipboard

Performs a deep clone of this IRR calculation's series of cash flows. All entries in the new / cloned list will be new / cloned cash flow entries. Refer: IRR.cloneCashFlows

fun cloneCashFlows(toCurr: CurrencyType, toDate: Int? = null): List<ROICashFlowEntry>?

Performs a deep clone of this IRR calculation's series of cash flows whilst also converting the currency and value(s). All entries in the new / cloned list will be new / cloned cash flow entries. Refer: IRR.cloneCashFlows

Link copied to clipboard
fun computeIRR(seedRate: Double = 0.1, strategies: List<IRR.SolveStrategy> = listOf(SolveStrategy.secant), reverseSeedOnFail: Boolean = false, clearResults: Boolean = true): List<IRR.CalculationResult>

Computes an annualised Internal Rate of Return (IRR), sometimes referred to as the Return on Investment (ROI), for a series of irregular cash flows. Supports multiple root-solving strategies.

Link copied to clipboard

Indicates how many successful IRR solutions were found

Link copied to clipboard

determines whether any calculations succeeded.

Link copied to clipboard
fun getIRR(): Double
fun getIRR(maxIRR: Double?): Double

returns the most recent IRR calculation result represented as a decimal, e.g. 0.15 = 15%.

Link copied to clipboard

returns the most recent IRR calculation result represented as a decimal, e.g. 0.15 = 15%.

Link copied to clipboard

returns the last IRR calculation result found out of all results, or null if none found.

Link copied to clipboard

returns a list of all IRR calculation results.

Link copied to clipboard

returns the last successful IRR calculation found out of all results, or null if none found.

Link copied to clipboard

returns a list of all successful IRR calculation results.

Link copied to clipboard

Validates the list of cash flows to ensure it meets ROI/IRR requirements:

Link copied to clipboard
fun logIRR(includeCashFlows: Boolean, includeResults: Boolean, dateFormatter: CustomDateFormat = CustomDateFormat("yyyy-MM-dd"), delimiter: String? = null)

Log IRR calculation object, its cashflows, and calculation result(s). This function makes no assumptions as to the validity of cashflows or results. The caller should ideally have called computeIRR prior to calling this method to obtain result(s).

Link copied to clipboard
fun setCashFlowsStartDate(startDateInt: Int)

Define the start date for this IRR calculation's series of cash flows (and thus compute/recompute the number of years to the end). This function calls ROICashFlowEntry.setStartDate on each cash flow entry.

Link copied to clipboard
open override fun toString(): String